package com.pingan.haofang.searchcloud.index.service;

import com.pingan.haofang.searchcloud.index.dto.IndexBuildIncDTO;
import com.pingan.haofang.searchcloud.index.dto.IndexBuildProgressDTO;
import com.pingan.haofang.searchcloud.indexdatasource.dto.IndexDatasourceDTO;
import org.quartz.JobExecutionContext;

import java.util.Date;
import java.util.List;

/**
 * 索引构建
 *
 * @author LUYI374
 * @date 2017年5月9日
 * @since 1.0.0
 */
public interface IndexBuildService {

    /**
     * 构建索引
     *
     * @param progressDTO
     * @param ignoreError
     * @param indexDatasourceList
     * @param jobExecutionContext
     */
    public void executeIndexBuild(IndexBuildProgressDTO progressDTO, boolean ignoreError,
                                  List<IndexDatasourceDTO> indexDatasourceList, JobExecutionContext
                                          jobExecutionContext ,boolean isResumeJob);

    /**
     * 增量写入索引
     *
     * @param message
     */
    public void executeIndexInc(IndexBuildIncDTO message);

    /**
     * 增量合并索引或增量写入索引
     *
     * @param message
     */
    public void mergeOrExecuteIndexInc(IndexBuildIncDTO message);

    /**
     * 加redis锁
     *
     * @param indexBuildDate
     * @param projectCode
     * @param indexName
     */
    public void lock(Date indexBuildDate, String projectCode, String indexName);

    /**
     * 解锁
     *
     * @param projectCode
     * @param indexName
     */
    public void unLock(String projectCode, String indexName);

    /**
     * 检测锁是否存在
     *
     * @param projectCode
     * @param indexName
     * @return
     */
    public boolean checkLock(String projectCode, String indexName);

    /**
     * 获取最近一次的锁定时间
     *
     * @param projectCode
     * @param indexName
     * @return
     */
    public long getLockTime(String projectCode, String indexName);


    /**
     * 增量数据合并
     *
     * @param message
     * @param maxTime
     */
    @Deprecated
    public void incMsgMerge(IndexBuildIncDTO message, long maxTime);

    /**
     * 增量合并数据处理
     *
     * @param key
     * @param maxSize
     */
    public void incMsgConsume(String key, long maxSize);

    /**
     * 构建后删除redis中的信息
     *
     * @param indexDatasourceList
     * @param progressId
     */
    void deleteProgressAfterIndexBuild(List<IndexDatasourceDTO> indexDatasourceList, Long progressId);

    /**
     * 获取LOCK KEY
     *
     * @param projectCode
     * @param indexName
     * @return
     */
     String getKey(String projectCode, String indexName);


}
